//
//  DiscountCollectionTableViewCell.m
//  Journey
//
//  Created by dllo on 16/5/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "DiscountCollectionTableViewCell.h"
#import "DiscountCollectionViewCell.h"
@interface DiscountCollectionTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,strong)BaseCollectionView *myCollectionView;
@end



@implementation DiscountCollectionTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createSubviews];
    }
    return self;
}

-(void)createSubviews
{
   
    self.dataArray = [NSMutableArray array];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(((WIDTH - 25) / 2 * WIDTHC), 180 * WIDTHC);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
   
    self.myCollectionView = [[BaseCollectionView alloc]initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
   self.myCollectionView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFFFF,0x363636);
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    [self.myCollectionView registerClass:[DiscountCollectionViewCell class] forCellWithReuseIdentifier:@"subjectCell"];
    [self.contentView addSubview:self.myCollectionView];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.myCollectionView.frame = CGRectMake(10 * WIDTHC, 10 * WIDTHC, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 20);
}
//cell数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArray.count;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DiscountCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"subjectCell" forIndexPath:indexPath];
    
  
    cell.discount = self.dataArray[indexPath.row];
    
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.discountBlock(indexPath.row );
   
 
}



-(void)setAllcountArray:(NSMutableArray *)allcountArray{
    _allcountArray = allcountArray;
    self.dataArray = [NSMutableArray arrayWithArray:_allcountArray];
    [self.myCollectionView reloadData];
}

@end
